package com.zmc.common.utils.redis.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.script.DefaultRedisScript;
import org.springframework.data.redis.core.script.RedisScript;

/**
 * @Author：zmc
 * @Date：2025/6/8 22:46
 * lua脚本解锁
 */
@Configuration
public class RedisLuaConfig {

    @Bean("redisUnLock")
    RedisScript<String> redisUnLock() {
        String luaScript = "local lockKey = KEYS[1];local lockValue = ARGV[1];if redis.call(\"GET\", lockKey)  == lockValue then    redis.call(\"DEL\", lockKey);    return 1;else    return 0;end";
        return new DefaultRedisScript<>(luaScript, String.class);
    }

}
